package com.dzk.cp.c11x5.index.cs.by;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.dzk.cp.c11x5.index.BaseC11x5Index;
import com.dzk.cp.c11x5.pojo.R5;
import com.dzk.cp.c11x5.util.SpringBeanUtils;

public abstract class CsByxIndex extends BaseC11x5Index {
	
	private String xc;

	protected CsByxIndex() {
		num = getZQ();
		unit = 1;
	}
	
	protected CsByxIndex setParams(int code, int num, int unit, String xc) {
		this.code = code;
		if (num > 0) this.num = num;
		if (unit > 0) this.unit = unit;
		this.xc = xc;
		return this;
	}
	
	@Override
	public Map<Integer, Integer> index() {
		Map<Integer, Integer> resultMap = new LinkedHashMap<Integer, Integer>();
		int n = getLastestNum();
		List<? extends R5> r5s = SpringBeanUtils.getR5Service(code).queryLatest(n);
		int m = n / num;
		for (int i = 0; i < num; i++) {
			resultMap.put(i + 1, getCS(r5s.subList(i * m, (i + 1) * m), xc));
		}
		return resultMap;
	}

	protected abstract Integer getCS(List<? extends R5> r5s, String xc);
	
	/**
	 * 玩法 1=任选 2=直选 3=组选
	 */
	public static CsByxIndex getInstance(int code, int num, int unit, String xc, int type) {
		switch (type) {
		case 1:
			return CsByxRXnIndex.getInstance(code, num, unit, xc);
		case 2:
			return CsByxZHXnIndex.getInstance(code, num, unit, xc);
		case 3:
			return CsByxZXnIndex.getInstance(code, num, unit, xc);
		default:
			return null;
		}
	}

}
